﻿drop table if exists proposals;
drop table if exists users;
drop table if exists idbms;

create table imdbs
(
	hash varchar(32) not null,
	value varchar(7) not null,
	timestamp datetime not null,
	user_id bigint null,
	primary key (hash),
	constraint foreign key (user_id) references users(id) on delete set null
);

create table users
(
	id bigint not null,
	login varchar(32) not null,
	password varchar(32) not null,
	timestamp datetime not null,
	rights int null,
	constraint primary key (id),
	constraint unique (login)
);

create table proposals
(
	user_id bigint not null,
	hash varchar(32) not null,
	value varchar(7) not null,
	timestamp datetime not null,
	constraint primary key (user_id, hash),
	constraint foreign key (user_id) references users(id) on delete cascade,
	index (hash)
);
